#include<iostream>
#include"ResourceSet.h"

namespace catan
{

// initializing all the resources to zero
ResourceSet::ResourceSet(): wood(0), sheep(0), wheat(0), brick(0), ore(0){}

// initializing the resources to the given paramenters
ResourceSet::ResourceSet(int theWood, int theSheep, int theWheat, int theBrick, int theOre){
	wood = theWood;
	sheep = theSheep;
	wheat = theWheat;
	brick = theBrick;
	ore = theOre;
}

ResourceSet::ResourceSet(CellType cellType): wood(0), sheep(0), wheat(0), brick(0), ore(0){
	switch (cellType.getEnum())
	{
	case CellType::FOREST_TYPE:
		wood = 1;
		break;
	case CellType::PASTURE_TYPE:
		sheep = 1;
		break;
	case CellType::FIELDS_TYPE:
		wheat = 1;
		break;
	case CellType::HILLS_TYPE:
		brick = 1;
		break;
	case CellType::MOUNTAINS_TYPE:
		ore = 1;
		break;
	default:
		break;
	}
}

// accessors that return the int value of the resources
int ResourceSet::getWood() const{
	return wood;
}
int ResourceSet::getSheep() const{
	return sheep;
}
int ResourceSet::getWheat() const{
	return wheat;
}
int ResourceSet::getBrick() const{
	return brick;
}
int ResourceSet::getOre() const{
	return ore;
}
bool ResourceSet::containsAtLeast(ResourceSet resourceSet){
	if(wood>=resourceSet.getWood() && sheep>=resourceSet.getSheep() && wheat>=resourceSet.getWheat() && brick>=resourceSet.getBrick() && ore>=resourceSet.getOre())
		return true;
	else
		return false;
}


const ResourceSet operator +(const ResourceSet& leftResourceSet, const ResourceSet& rightResourceSet){
	return ResourceSet(leftResourceSet.wood+rightResourceSet.wood, leftResourceSet.sheep+rightResourceSet.sheep, leftResourceSet.wheat+rightResourceSet.wheat, leftResourceSet.brick+rightResourceSet.brick,leftResourceSet.ore+rightResourceSet.ore);
}

const ResourceSet operator- (const ResourceSet& leftResourceSet, const ResourceSet& rightResourceSet){
	// the condition if(leftResourceSet.containsAtLeast(rightResourceSet) must be checked when "-" is called
	return ResourceSet(leftResourceSet.wood-rightResourceSet.wood, leftResourceSet.sheep-rightResourceSet.sheep, leftResourceSet.wheat-rightResourceSet.wheat, leftResourceSet.brick-rightResourceSet.brick,leftResourceSet.ore-rightResourceSet.ore);
}
const ResourceSet operator* (const ResourceSet& leftResourceSet, const int& rightInteger){
	return ResourceSet(leftResourceSet.wood*rightInteger, leftResourceSet.sheep*rightInteger, leftResourceSet.wheat*rightInteger, leftResourceSet.brick*rightInteger, leftResourceSet.ore*rightInteger);
}

const bool operator== (const ResourceSet& leftResourceSet, const ResourceSet& rightResourceSet){
	return
		leftResourceSet.wood == rightResourceSet.wood &&
		leftResourceSet.sheep == rightResourceSet.sheep &&
		leftResourceSet.wheat == rightResourceSet.wheat &&
		leftResourceSet.brick == rightResourceSet.brick &&
		leftResourceSet.ore == rightResourceSet.ore;
}

void ResourceSet::printResourceSet(){
	std::cout<<"wood: "<<wood<<", sheep: "<<sheep<<", wheat: "<<wheat<<", brick: "<<brick<<", ore: "<<ore<<std::endl;
}

}
